package com.xiaoq;

import java.io.FileInputStream;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.io.ByteArrayOutputStream;

import bitoflife.chatterbean.AliceBot;
import bitoflife.chatterbean.Context;
import bitoflife.chatterbean.parser.AliceBotParser;
import bitoflife.chatterbean.util.Searcher;

@Component
public class AliceBotMother
{

  @Bean
  public AliceBot newInstance() {
    Searcher searcher = new Searcher();
    AliceBotParser parser;
    AliceBot bot = null;
	try {
		parser = new AliceBotParser();
		bot = parser.parse(
				getClass().getClassLoader().getResourceAsStream("Bots/context.xml"),
				getClass().getClassLoader().getResourceAsStream("Bots/splitters.xml"),
				getClass().getClassLoader().getResourceAsStream("Bots/substitutions.xml"),
				getClass().getClassLoader().getResourceAsStream("Bots/mydomain/idiom.aiml"));
	} catch (Exception e) {
		e.printStackTrace();
	}
	
    Context context = bot.getContext(); 
    ByteArrayOutputStream gossip = new ByteArrayOutputStream();
    context.outputStream(gossip);
    bot.respond("welcome");
    return bot;
  }
}
